using Microsoft.AspNetCore.Mvc;
using ZR.Admin.WebApi.Filters;
using ZR.Model.Dto.Business.ProductionControl;
using ZR.Model.Models.ProductionControl;
using ZR.Service.IService.ProductionControl;

//创建时间：2024-10-20
namespace ZR.Admin.WebApi.Controllers
{
    /// <summary>
    /// 设备工位绑定关系表
    /// </summary>
    [Verify]
    [Route("device/DeviceBinding")]
    [ApiExplorerSettings(GroupName = "business")]
    public class DeviceBindingController : BaseController
    {
        /// <summary>
        /// 设备工位绑定关系表接口
        /// </summary>
        private readonly IDeviceBindingService _DeviceBindingService;

        public DeviceBindingController(IDeviceBindingService DeviceBindingService)
        {
            _DeviceBindingService = DeviceBindingService;
        }

        /// <summary>
        /// 查询设备工位绑定关系表列表
        /// </summary>
        /// <param name="parm"></param>
        /// <returns></returns>
        [HttpGet("list")]
        [ActionPermissionFilter(Permission = "devicebinding:list")]
        public IActionResult QueryDeviceBinding([FromQuery] DeviceBindingQueryDto parm)
        {
            var response = _DeviceBindingService.GetList(parm);
            return SUCCESS(response);
        }

        /// <summary>
        /// 查询设备工位绑定关系表详情
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        [HttpGet("{Id}")]
        [ActionPermissionFilter(Permission = "devicebinding:query")]
        public IActionResult GetDeviceBinding(int Id)
        {
            var response = _DeviceBindingService.GetInfo(Id);

            var info = response.Adapt<DeviceBindingDto>();
            return SUCCESS(info);
        }

        /// <summary>
        /// 添加设备工位绑定关系表
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [ActionPermissionFilter(Permission = "devicebinding:add")]
        [Log(Title = "设备工位绑定关系表", BusinessType = BusinessType.INSERT)]
        public IActionResult AddDeviceBinding([FromBody] DeviceBindingDto parm)
        {
            var modal = parm.Adapt<DeviceBinding>().ToCreate(HttpContext);

            var response = _DeviceBindingService.AddDeviceBinding(modal);

            return SUCCESS(response);
        }

        /// <summary>
        /// 更新设备工位绑定关系表
        /// </summary>
        /// <returns></returns>
        [HttpPut]
        [ActionPermissionFilter(Permission = "devicebinding:edit")]
        [Log(Title = "设备工位绑定关系表", BusinessType = BusinessType.UPDATE)]
        public IActionResult UpdateDeviceBinding([FromBody] DeviceBindingDto parm)
        {
            var modal = parm.Adapt<DeviceBinding>().ToUpdate(HttpContext);
            var response = _DeviceBindingService.UpdateDeviceBinding(modal);

            return ToResponse(response);
        }

        /// <summary>
        /// 删除设备工位绑定关系表
        /// </summary>
        /// <returns></returns>
        [HttpDelete("delete/{ids}")]
        [ActionPermissionFilter(Permission = "devicebinding:delete")]
        [Log(Title = "设备工位绑定关系表", BusinessType = BusinessType.DELETE)]
        public IActionResult DeleteDeviceBinding([FromRoute] string ids)
        {
            var idArr = Tools.SplitAndConvert<int>(ids);

            return ToResponse(_DeviceBindingService.Delete(idArr));
        }
    }
}